package gob.inei.enaho.model.service;

import java.sql.SQLException;

import util.android.sqlite.SQLiteUtil;
import util.form.respuesta.RegistroImpl;
import util.www.sql.InsertSql;
import util.www.sql.UpdateSql;
import android.database.sqlite.SQLiteOpenHelper;

public abstract class AbstractService 
implements Service
{
	
	protected abstract String getNombreTabla();
	
	private SQLiteOpenHelper openHelper;

	public SQLiteOpenHelper getOpenHelper() {
		return openHelper;
	}

	public void setOpenHelper(SQLiteOpenHelper openHelper) {
		this.openHelper = openHelper;
	}
	

	public void guardar(RegistroImpl registro) throws SQLException {
		InsertSql i = new InsertSql(getNombreTabla());
		i.agregar(registro);
		SQLiteUtil.executeUpdate(getOpenHelper(), i.getSql());		
	}

	public void actualizar(RegistroImpl registro) throws SQLException {
		String[] claves = SQLiteUtil.getColumnasClave(getOpenHelper(), getNombreTabla());
		UpdateSql u = new UpdateSql(getNombreTabla(),claves);
		u.agregar(registro);
		SQLiteUtil.executeUpdate(getOpenHelper(), u.getSql());
	}
	
	
}
